﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using MySql.Data.MySqlClient;

/// <summary>
/// RewardDB 的摘要说明
/// </summary>
public class RewardDB : CommonDb
{
	public RewardDB()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public RewardDetail[] GetRewards()
    {
        MySqlCommand cmd = DataComponent.CreateMySqlProcCmd("GetRewards", m_conn);

        ArrayList Rewards = new ArrayList();
        
        try
        {
            m_conn.Open();
            MySqlDataReader reader = cmd.ExecuteReader();

            while(reader.Read())
            {
                RewardDetail reward = new RewardDetail();
                reward.Id = (uint)reader["Id"];
                reward.Level = (uint)reader["Level"];
                reward.EvalHigh = (uint)reader["EvalHigh"];
                reward.EvalMiddle = (uint)reader["EvalMiddle"];
                reward.EvalLow = (uint)reader["EvalLow"];
                Rewards.Add(reward);
            }
            reader.Close();
            return (RewardDetail[])Rewards.ToArray(typeof(RewardDetail));
        }
        catch(MySqlException err)
        {
            throw new ApplicationException("Data err:" + err.ToString());
        }
        finally
        {
            m_conn.Close();
        }
    }

    public void UpdateReward(RewardDetail rewardInfo)
    {
        MySqlCommand cmd = DataComponent.CreateMySqlProcCmd("UpdateRewards", m_conn);
        DataComponent.AddCmdParameters(cmd, "?uId", MySqlDbType.Int32, 10, rewardInfo.Id);
        DataComponent.AddCmdParameters(cmd, "?uLevel", MySqlDbType.Int32, 10, rewardInfo.Level);
        DataComponent.AddCmdParameters(cmd, "?uHigh", MySqlDbType.Int32, 10, rewardInfo.EvalHigh);
        DataComponent.AddCmdParameters(cmd, "?uMiddle", MySqlDbType.Int32, 10, rewardInfo.EvalMiddle);
        DataComponent.AddCmdParameters(cmd, "?uiLow", MySqlDbType.Int32, 10, rewardInfo.EvalLow);

        DataComponent.ExecNonQueryCmd(cmd, m_conn);
    }
}
